package com.jxt.myjxtmanager.utils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.TimeZone;

/**
 * Created by Administrator on 2016/1/26 0026.
 * <p/>
 * 时间转换
 */
public class TimeCalculate {

    static SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
    static SimpleDateFormat format2 = new SimpleDateFormat("yyyy-MM");
    static SimpleDateFormat format3 = new SimpleDateFormat("yyyy-MM-dd  HH:mm:ss");


    private static String mYear;
    private static String mMonth;
    private static String mDay;
    private static String mWay;

    /**
     * 字符串转时间戳
     *
     * @param time 格式 yyyy-MM-dd
     * @return long
     */
    public static Long getFormatTime(String time) {
        Date date = null;
        Calendar cal = Calendar.getInstance();

        try {
            date = format.parse(time);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        cal.setTime(date);
        return cal.getTimeInMillis();
    }


    /**
     * 时间戳转字符串
     *
     * @param time 格式 yyyy-MM-dd
     * @return String
     */
    public static String getFormatTime(long time) {
        return format.format(time);
    }

    /**
     * 时间戳转字符串
     *
     * @param time 格式 yyyy-MM
     * @return String
     */
    public static String getFormatNotDay(long time) {
        return format2.format(time);
    }


    /**
     * 获取当前时间
     *
     * @return String 格式 yyyy-MM-dd
     */
    public static String getCurrentTime() {
        return format.format(System.currentTimeMillis());
    }

    /**
     * 获取时间
     *
     * @param time
     * @return yyyy-MM-dd  hh:mm:ss
     */
    public static String getFormatTimeAll(long time) {
        return format3.format(time);
    }


    public static String StringData() {
        final Calendar c = Calendar.getInstance();
        c.setTimeZone(TimeZone.getTimeZone("GMT+8:00"));
        mYear = String.valueOf(c.get(Calendar.YEAR)); // 获取当前年份
        mMonth = String.valueOf(c.get(Calendar.MONTH) + 1);// 获取当前月份
        mDay = String.valueOf(c.get(Calendar.DAY_OF_MONTH));// 获取当前月份的日期号码
        mWay = String.valueOf(c.get(Calendar.DAY_OF_WEEK));
        if ("1".equals(mWay)) {
            mWay = "天";
        } else if ("2".equals(mWay)) {
            mWay = "一";
        } else if ("3".equals(mWay)) {
            mWay = "二";
        } else if ("4".equals(mWay)) {
            mWay = "三";
        } else if ("5".equals(mWay)) {
            mWay = "四";
        } else if ("6".equals(mWay)) {
            mWay = "五";
        } else if ("7".equals(mWay)) {
            mWay = "六";
        }
        return mYear + "年" + mMonth + "月" + mDay + "日" + "     星期" + mWay;
    }


}
